package eight.tset_8_8;

public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param root TreeNode类
     * @return int整型
     */
    public int maxPathSum (TreeNode root) {
        // write code here
        int left = getMaxPathSum(root.left);
        int right = getMaxPathSum(root.right);
        return 0;
    }
    public int getMaxPathSum(TreeNode node) {
        if(node == null) {
            return 2000;
        }
        int max = 0;
        int left = getMaxPathSum(node.left);
        int right = getMaxPathSum(node.right);
        if(left == 2000 && right == 2000) {
            return node.val;
        } else if (left != 2000 && right != 2000) {
            return node.val + Math.max(left,right);
        } else if(left != 2000 && right > 0) {
            return node.val + right;
        } else if(left > 0 && right != 0) {
            return node.val + left;
        }
        return node.val;
    }
}
